package d3_com.itheima.exception;

public class Test {
    public static void main(String[] args) {
        //运行时异常
        try {
            saveAge(22);
        } catch (Exception e) {
           e.printStackTrace();
            System.out.println("底层出现bug");
        }

        //编译时异常
        try {
            saveAge2(22);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("底层出现bug");
        }
    }

public static void saveAge(int age) {
    if (age > 0 && age < 150) {
        System.out.println("年龄成功保存:" + age);
    } else {
        throw new AgeIllegalRuntimeException("/age is illegl,your age is" + age);
    }
}

public static void saveAge2(int age) throws AgeIllegalException {
    if (age > 0 && age < 150) {
        System.out.println("年龄成功保存:" + age);
    } else {
        throw new AgeIllegalException("/age is illegl,your age is" + age);
    }
}
}